package net.wanho.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.wanho.po.AuthInfo;
import net.wanho.service.AuthInfoService;
import net.wanho.mapper.AuthInfoMapper;
import net.wanho.vo.AuthVO;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
* @author 王洋
* @description 针对表【auth_info(权限表)】的数据库操作Service实现
* @createDate 2024-09-03 17:43:36
*/
@Service
public class AuthInfoServiceImpl extends ServiceImpl<AuthInfoMapper, AuthInfo>
    implements AuthInfoService{

    @Override
    public List<AuthInfo> authlist() {

        List<AuthInfo> list = this.list();
        List<AuthInfo> collect = list.stream().filter(item -> item.getParentId() == 0)
                .map(item -> {
                    findChildren(list, item);
                    return item;
                }).collect(Collectors.toList());
        return collect;
    }
    private void findChildren(List<AuthInfo> list, AuthInfo item) {
        List<AuthInfo> children = list.stream().
                filter(subItem -> subItem.getParentId().equals(item.getAuthId()))
                .map(subItem -> {
                    findChildren(list, subItem);
                    return subItem;
                }).collect(Collectors.toList());
        item.setChildAuth(children);
    }
}




